package com.example.demo.service;

import com.example.demo.entity.Student;
import com.example.demo.entity.Grade;
import com.example.demo.repository.StudentRepository;
import com.example.demo.repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class StudentService {
    @Autowired
    private StudentRepository studentRepository;
    
    @Autowired
    private GradeRepository gradeRepository;
    
    public List<Student> findAll() {
        return studentRepository.findAll();
    }
    
    public Student findById(Long id) {
        return studentRepository.findById(id)
            .orElseThrow(() -> new RuntimeException("学生不存在"));
    }
    
    public List<Grade> findGradesByStudentId(Long studentId) {
        return gradeRepository.findByStudentId(studentId);
    }
    
    public Student save(Student student) {
        return studentRepository.save(student);
    }
} 